package com.qu.OperatorSqlite;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.qu.OperatorSqlite.db.DBManager;
import com.qu.OperatorSqlite.db.Person;

import java.util.List;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.test_one: //创建数据库
                DBManager.getInstance().create(Person.class);
                break;
            case R.id.test_two: //插入数据
                insert();
                break;
            case R.id.test_three:
                Toast.makeText(this,"test_three",Toast.LENGTH_SHORT).show();
                break;
            case R.id.test_four: //查询数据
                List<Person> person = DBManager.getInstance().get(Person.class);
                Toast.makeText(this,"查询数据的个数---"+person.get(0).getName(),Toast.LENGTH_SHORT).show();
                break;
            case R.id.test_five:
                Toast.makeText(this,"test_five",Toast.LENGTH_SHORT).show();
                break;
            case R.id.test_six:
                Toast.makeText(this,"test_six",Toast.LENGTH_SHORT).show();
                break;
            case R.id.test_seven:
                Toast.makeText(this,"test_seven",Toast.LENGTH_SHORT).show();
                break;
            case R.id.test_eight:
                Toast.makeText(this,"test_eight",Toast.LENGTH_SHORT).show();
                break;
        }
    }

    //插入一条数据
    public void insert(){
         Person person = new Person();
         person.setId(1);
         person.setName("屈光乐");
         person.setAge(23);
         person.setAddress("武汉市司门口雄楚楼97号");
         person.setSchool("毕业于湖北工业大学");
         person.setShanchang("写代码，打篮球");
         person.setInterest("看NBA,写代码，玩王者荣耀");
         Boolean isInsert = DBManager.getInstance().insert(person);
         Toast.makeText(this,"插入数据是否成功:--"+isInsert,Toast.LENGTH_SHORT).show();
    }
}
